﻿package com.crl.module.media.player{
	
	import com.crl.module.media.core.LNetConnection;
	
	import flash.display.*;
	import flash.events.*;
	import flash.media.SoundTransform;
	import flash.media.Video;
	import flash.net.*;
	
	
	/**
	 * this.stream.time 当前播放时间;
	 * @author crl
	 * 
	 */	
	
	public class VideoPlayer extends AbstractPlayer implements IPlayer {
		public var video:Video;
		private var connection:LNetConnection;
		private var stream:NetStream;
		
		public var autowidth:int;
		//构造器;
		public function VideoPlayer() {
		}
		//初始化;
		override protected function init():void {
			this.video = new Video();
			
			this.connection=new LNetConnection;
            this.connection.connect(null);
		}
		
		private function connectStream():void {
            this.stream= connection.stream;
            this.stream.bufferTime=5;
            this.video.attachNetStream(this.stream);
        }
		private function onMetaData(e:DataEvent):void{
			/*this.video.width=this.autowidth;
			this.video.height=this.autowidth/this.client.WHavg;*/
		}
		
		/**
		* Adapter;
		* @param	path
		* @return
		*/
		
		public function load(path:String):void{
			this._currentPath = path;
		}

		public function play(position:int=0):void {
			this.stream.play(_currentPath);
			this.position=position;
		}
		
		public function pause():void{
			this.stream.pause();
		}
		public function togglePause():void{
			this.stream.togglePause();
		}
		public function close():void{
			this.stream.close();
			this.connection.close();
			this.video.clear();
		}
		public function stop():void{
			//this.position=0;
		}

	
		public function get totalTime():Number{
			return this.connection.duration;
		}
		
		
		public function get position():Number{
			return this.stream.time;
		}
		
		public function set position(value:Number):void{
			this.stream.seek(value);
		}
		
		public function set volume(value:Number):void{
			var soundTransform:SoundTransform=this.stream.soundTransform;
			soundTransform.volume=value;
			
			this.stream.soundTransform=soundTransform;
		}
		public function get volume():Number{
			return this.stream.soundTransform.volume;
		}
		
		public function getMediaBytesLoaded():int{
			return this.stream.bytesLoaded;
		}
		public function getMediaBytesTotal():int{
			return this.stream.bytesTotal;
		}
		public function getSoundTransform():SoundTransform{
			return this.stream.soundTransform;
		}
		public function setSoundTransform(trans:SoundTransform):void{
			this.stream.soundTransform=trans;
		}
	}
}